package com.zwr.sheller.shop.service.impl;

import com.zwr.sheller.core.pojo.Discount;
import com.zwr.sheller.shop.mapper.DiscountMapper;
import com.zwr.sheller.shop.service.DiscountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 *
 *@author Kang
 *@date
 */
@Service("discountService")
public class DiscountServiceImpl implements DiscountService {

    @Autowired(required = false)

    DiscountMapper discountMapper;

    @Override
    public Integer add(Discount discount) {
        Long marketersId = 1L;
        discount.setMarketersId(marketersId);
        int insert = discountMapper.insert(discount);

        return insert;
    }

    @Override
    public Integer delete(Long id) {
        Discount discount=new Discount();
        discount.setId(id);
        int delete = discountMapper.delete(discount);

        return delete;
    }

    @Override
    public Integer update(Discount discount) {
        int i = discountMapper.updateByPrimaryKeySelective(discount);
        return i;
    }

    @Override
    public List<Map<String, Object>> selectDiscountByNameByTimeByManner(Integer manner, Integer timePeriod, String name,  Integer page) {
        Long marketersId = 1L;
        List<Map<String, Object>> mapList = discountMapper.selectDiscountByNameByTimeByManner(manner, timePeriod, name, marketersId, (page - 1) * 3);

        return mapList;
    }

    @Override
    public Map selectDiscountByNameByTimeByMannerCount(Integer manner, Integer timePeriod, String name) {

        Long marketersId = 1L;
        Map map = discountMapper.selectDiscountByNameByTimeByMannerCount(manner, timePeriod, name, marketersId);

        return map;
    }
}
